//
//  MyPictureCollectionViewCell.m
//  myselfTest
//
//  Created by Lucifer on 15-5-21.
//  Copyright (c) 2015年 xuxzhou. All rights reserved.
//

#import "MyPictureCollectionViewCell.h"
#define color_hex(hex) ([UIColor colorWithRed:(hex >> 16 & 0x0000ff) / 255.0 green:(hex >> 8 & 0x0000ff) / 255.0 blue:(hex & 0x0000ff) / 255.0 alpha:1.0])
@implementation MyPictureCollectionViewCell
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.imageView = [[UIImageView alloc] init];
        [self addSubview:self.imageView];
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    self.imageView.frame = CGRectMake(0, 0, CGRectGetWidth(self.frame), CGRectGetHeight(self.frame));
}

- (void)setImage:(UIImage*)image
{
    _image = image;
    self.imageView.image = image;
}

- (void)setIndexPath:(NSIndexPath*)indexPath
{
    _indexPath = indexPath;
    
    CGColorRef lineColor = color_hex(0xdcdcdc).CGColor;
    //上
    CALayer* line1 = [[CALayer alloc] init];
    line1.frame = CGRectMake(0, 0, CGRectGetWidth(self.frame), 0.5);
    line1.backgroundColor = lineColor;
    //下
    CALayer* line2 = [[CALayer alloc] init];
    line2.frame = CGRectMake(0, CGRectGetHeight(self.frame) - 0.5, CGRectGetWidth(self.frame) + 0.5, 0.5);
    line2.backgroundColor = lineColor;
    //←
    CALayer* line3 = [[CALayer alloc] init];
    line3.frame = CGRectMake(0, 0, 0.5, CGRectGetHeight(self.frame));
    line3.backgroundColor = lineColor;
    //→
    CALayer* line4 = [[CALayer alloc] init];
    line4.frame = CGRectMake(CGRectGetWidth(self.frame) - 0.5, 0, 0.5, CGRectGetHeight(self.frame) + 0.5);
    line4.backgroundColor = lineColor;
    
    NSInteger index = indexPath.row;
    if (index % 3 == 2) {
        [self.layer addSublayer:line2];
    }
    if (index % 3 == 0) {
        [self.layer addSublayer:line2];
        [self.layer addSublayer:line4];
    }
    if (index % 3 == 1) {
        [self.layer addSublayer:line2];
        [self.layer addSublayer:line4];
    }
}

@end
